/**
 * SSTableRenderer.java
 */
package com.pluginsacceptor.plugin.spreadsheet.table;

import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import com.pluginsacceptor.plugin.spreadsheet.model.Cell;

/**
 * The rendere
 */
public class SSTableRenderer extends DefaultTableCellRenderer {

    /**
     *
     */
    private static final long serialVersionUID = -1491118477543709122L;

    @Override
    public Component getTableCellRendererComponent(
        final JTable table, final Object value, final boolean isSelected,
         final boolean hasFocus, final int row, final int column
    ) {

        if (value instanceof Cell){
            final Cell label = (Cell) value;
            label.setOpaque(true);
            fillColor(table, label, isSelected);
            return label;
        } else {
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        }

     }

    public void fillColor(final JTable t, final Cell l,final boolean isSelected ){
        //setting the background and foreground when JLabel is selected
        if(isSelected){
            l.setBackground(t.getSelectionBackground());
        } else{
            l.setBackground(t.getBackground());
        }

    }

}
